package com.yly.input.demo.controller;

import com.yly.input.demo.converter.ControllerConverter;
import com.yly.input.demo.dto.ElderDTO;
import com.yly.input.demo.service.ElderService;
import com.yly.input.demo.vo.ElderVO;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Log4j2
@RequestMapping("/elder")
public class DemoController {

  private final ElderService elderService;

  private final ControllerConverter converter;

  @Autowired
  public DemoController(ElderService elderService, ControllerConverter converter) {
    this.elderService = elderService;
    this.converter = converter;
  }

  @PostMapping
  public void addElder(@RequestBody ElderDTO elderDTO) {
    log.info("-------------addElder");
//        elderService.addElder(converter.toElderBO(elderDTO));
  }

  @GetMapping
  public List<ElderVO> getElders(HttpServletRequest request) {
    log.info("userId-----:" + request.getHeader("UserId"));
    log.info("userName-----:" + request.getHeader("UserName"));
    log.info("token-----:" + request.getHeader("token"));
    return elderService.getElders();
  }
}
